home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / xconf / section.c < prev    next >
C/C++ Source or Header  |  1995-02-12  |  2KB  |  113 lines

  1. #include <string.h>
  2. #include <stdlib.h>
  3. #include "xconf.h"
  4. #include "section.h"
  5.  
  6. PUBLIC PAIRES::PAIRES(
  7.     const char *keyword,
  8.     const char *value)
  9. {
  10.     keyw = strdup(keyword);
  11.     arg  = strdup(value);
  12. }
  13. PUBLIC VIRTUAL PAIRES::~PAIRES()
  14. {
  15.     free (keyw);
  16.     free (arg);
  17. }
  18.  
  19.  
  20. PUBLIC OPTION::OPTION(
  21.     const char *keyword,
  22.     const char *value)
  23.     : PAIRES (keyword,value)
  24. {
  25. }
  26. /*
  27.     Merge an OPTION into another
  28. */
  29. PUBLIC VIRTUAL void OPTION::merge (const OPTION *src)
  30. {
  31.     free (arg);
  32.     arg = strdup(src->arg);
  33. }
  34.  
  35. /*
  36.     Make a copy of itself
  37. */
  38. PUBLIC VIRTUAL OPTION *OPTION::clone() const
  39. {
  40.     return new OPTION (keyw,arg);
  41. }
  42. /*
  43.     Formatte and output an option and suboption in ascii
  44. */
  45. PUBLIC VIRTUAL void OPTION::print (FILE *fout) const
  46. {
  47.     fprintf (fout,"%s %s\n",keyw,arg);
  48. }
  49.  
  50. /*
  51.     Validate the option value and suboption
  52.     Return -1 if something is wrong. msg will contain an explanation.
  53.  
  54.     The default is to allow anything.
  55. */
  56. PUBLIC VIRTUAL int OPTION::validate (char *msg)
  57. {
  58.     msg[0] = '\0';
  59.     return 0;
  60. }
  61. /*
  62.     Get one OPTION of the table or NULL
  63. */
  64. PUBLIC OPTION *OPTIONS::getitem(int no) const
  65. {
  66.     return (OPTION*)ARRAY::getitem(no);
  67. }
  68.  
  69. /*
  70.     Formatte and output an option and suboption in ascii
  71. */
  72. PUBLIC VIRTUAL void OPTIONS::print (FILE *fout,int indent) const
  73. {
  74.     for (int i=0; i<getnb(); i++){
  75.         for (int j=0; j<indent; j++) fputc ('\t',fout);
  76.         getitem(i)->print (fout);
  77.     }
  78. }
  79.  
  80. PUBLIC SECTION::SECTION(const char *_name)
  81. {
  82.     name = strdup(_name);
  83. }
  84. PUBLIC VIRTUAL SECTION::~SECTION()
  85. {
  86.     free (name);
  87. }
  88.  
  89. /*
  90.     Formatte and output an option and suboption in ascii
  91. */
  92. PUBLIC void SECTION::print (FILE *fout,int indent) const
  93. {
  94.     fprintf (fout,"Section \"%s\"\n",name);
  95.     OPTIONS::print(fout,indent);
  96.     fprintf (fout,"EndSection\n");
  97. }
  98.  
  99. /*
  100.     Validate all suboption of a section.
  101.     Return -1 if any error. Error messages will be appended
  102.     in msg.
  103. */
  104. PUBLIC int SECTION::validate (char *msg)
  105. {
  106.     int ret = 0;
  107.     for (int i=0; i<getnb(); i++){
  108.         ret |= getitem(i)->validate (msg);
  109.     }
  110.     return ret;
  111. }
  112.  
  113.